<?php


namespace App\Http\Controllers\Client;


use App\Http\Controllers\Controller;
use App\Services\ThreeDMap\InfoSpotService;
use App\Services\ThreeDMap\MapService;
use App\Services\ThreeDMap\PanoramaService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class MapController extends Controller
{
    protected $mapService;
    private PanoramaService $panoramaService;
    private InfoSpotService $infoSpotService;

    public function __construct(MapService $mapService,PanoramaService $panoramaService,InfoSpotService $infoSpotService)
    {
        $this->mapService = $mapService;
        $this->panoramaService = $panoramaService;
        $this->infoSpotService = $infoSpotService;
    }

    /**
     * 获取列表
     * @param Request $request
     * @return JsonResponse
     */
    public function getMapStart(Request $request)
    {

        // 定义业务参数验证规则
        $paramRule = [
            'guid' => 'string',
        ];

        // 验证参数
        $validateResult = $this->validateParam($request, $paramRule);

        // 根据验证结果确定是否返回响应还是获取业务参数
        if ($validateResult['status']) {
            // 获取验证后的业务参数
            $params = $validateResult['result'];
        } else {
            return $this->returnErrorResponse($validateResult['msg'], 40010);
        }

        $res = $this->mapService->getMapStart($params['guid']);

        if ($res['status']) {

            return $this->returnResponse($res['data']);
        }
        return $this->returnErrorResponse($res['data'], $res['code']);
    }

    /**
     * 获取列表
     * @param Request $request
     * @return JsonResponse
     */
    public function getPanoramaInfo(Request $request)
    {

        // 定义业务参数验证规则
        $paramRule = [
            'guid' => 'string',
        ];

        // 验证参数
        $validateResult = $this->validateParam($request, $paramRule);

        // 根据验证结果确定是否返回响应还是获取业务参数
        if ($validateResult['status']) {
            // 获取验证后的业务参数
            $params = $validateResult['result'];
        } else {
            return $this->returnErrorResponse($validateResult['msg'], 40010);
        }

        $res = $this->panoramaService->getPanoramaInfo($params['guid']);

        if ($res['status']) {

            return $this->returnResponse($res['data']);
        }
        return $this->returnErrorResponse($res['data'], $res['code']);
    }

    /**
     * 获取列表
     * @param Request $request
     * @return JsonResponse
     */
    public function allPanorama(Request $request): JsonResponse
    {

        // 定义业务参数验证规则
        $paramRule = [
            'guid' => 'string|size:32',
            'map_id' => 'string|size:32',
            'name' => 'string|max:255',
            'status' => 'integer',
        ];

        // 验证参数
        $validateResult = $this->validateParam($request, $paramRule);

        // 根据验证结果确定是否返回响应还是获取业务参数
        if ($validateResult['status']) {
            // 获取验证后的业务参数
            $params = $validateResult['result'];
        } else {
            return $this->returnErrorResponse($validateResult['msg'], 40010);
        }

        $res = $this->panoramaService->all($params);

        if ($res['status']) {

            return $this->returnResponse($res['data']);
        }
        return $this->returnErrorResponse($res['data'], $res['code']);
    }


}
